#ifndef RSAGRICUTUREDROUGHTWATERLOGGING_H
#define RSAGRICUTUREDROUGHTWATERLOGGING_H

#include "rsagricuturedroughtwaterlogging_global.h"
#include "rsalgorithm.h"
#include "gdal_priv.h"

class RSAGRICUTUREDROUGHTWATERLOGGINGSHARED_EXPORT RSAgricutureDroughtWaterlogging : public RSAlgorithm
{

public:
    RSAgricutureDroughtWaterlogging();
    ~RSAgricutureDroughtWaterlogging();

    /*!
     * \brief setNewInputImg 设置输出影像全路径
     * \param pNewInputImg
     * \return
     */
    bool setNewInputImg(const char* pNewInputImg);

    /*!
     * \brief setFlag 设置计算方式，详细请见Flag说明
     * \param nFlag 如果等于0，则表示计算旱情，如果大于0，则表示计算水灾区
     */
    void setFlag(const int nFlag);

    /*!
     * \brief setOutputImgFormat 设置输出格式
     * \param pImgFormat 与GDAL字符串对应，如tif格式对应“GTiff”
     */
    void setOutputImgFormat(const char* pImgFormat);

    double getNDVI() const;

    /*!
     * \brief disPose 算法处理过程
     * \return
     */
    virtual bool disPose();


private:
    // 计算NDVI
    /*!
     * \brief calculateNDVI
     * \param poDataset
     * \param xsize
     * \param ysize
     * \return
     */
    float * calculateNDVI(GDALDataset *poDataset, int xsize, int ysize);

    // 计算平均值
    /*!
     * \brief mean
     * \param pdata
     * \param nxsize
     * \param nysize
     * \return
     */
    float mean(short* pdata, int nxsize, int nysize);

    // 获取最大值
    /*!
     * \brief getMax
     * \param but
     * \return
     */
    float getMax(float* but);

    // 获取最小值
    /*!
     * \brief getMin
     * \param buff
     * \return
     */
    float getMin(float* buff);

    /*!
     * \brief saveImageproj
     * \param adfGeoTransform
     * \param proj
     * \param buf
     * \param outputFileName
     * \return
     */
    int saveImageproj(double *adfGeoTransform,const char * proj,unsigned char *buf,
                       const char * outputFileName);

    // 用Landsat8数据计算水域
    /*!
     * \brief landsat8Flood
     * \param poDataset
     * \param xsize
     * \param ysize
     * \return
     */
    bool * landsat8Flood(GDALDataset *poDataset, int xsize, int ysize);

    //modis计算水域
    /*!
     * \brief modisFlood
     * \param poDataset
     * \param xsize
     * \param ysize
     * \return
     */
    bool * modisFlood(GDALDataset *poDataset, int xsize, int ysize);

protected:
    /*!
     * \brief m_ImgWidth 影像宽和高
     */
    int m_ImgWidth;
    int m_ImgHeight;

    /*!
     * \brief m_pNDVI NDVI值
     */
    float* m_pNDVI;
    unsigned char* m_pVSWI;
    unsigned char* m_pFloodArea;

    /*!
     * \brief m_NewInputImg 输出影像全路径
     */
    std::string m_NewInputImg;

    /*!
     * \brief m_Flag 如果等于0，则表示计算旱情，如果大于0，则表示计算水灾区
     */
    int m_Flag;

    /*!
     * \brief m_pszFileout 输出文件的格式
     */
    std::string m_pszFileout;
};

#endif // RSAGRICUTUREDROUGHTWATERLOGGING_H
